package com.common.domain.vo;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.time.Duration;
import java.time.LocalDateTime;

/**
 * @author liuxuhuang
 * @date 2023年04月21日 11:19
 * @desc 维修记录返回
 */
@Data
@EqualsAndHashCode
@Accessors(chain = true)
public class MainTainVO implements Serializable, Comparable {
    /**
     * id
     */
    private Integer id;

    /**
     * 宿舍id
     */
    private long dormId;
    /**
     * 宿舍名称
     */
    private String dormName;
    /**
     * 内容
     */
    private String context;

    private String picture;
    /**
     * 添加时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    private LocalDateTime addTime;

    /**
     * 修理反馈
     */
    private String feedback;

    /**
     * 修理者姓名
     */
    private String handleWorkName;

    /**
     * 修理时间
     */
    @TableField(value = "handle_time")
    private LocalDateTime handleTime;

    /**
     * 判断该条记录能否删除，修改
     */
    private boolean isDeleteUpdate;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    @Override
    public int compareTo(Object o) {
        MainTainVO vo = (MainTainVO) o;
        long nanos = Duration.between(vo.getAddTime(), addTime).toNanos();
        if (nanos > 0) {
            return 1;
        }
        return 0;
    }
}
